<?php
namespace Home\Controller;

use Think\Controller;

class PostCommandController extends Controller{

    public function insert($tableName){
        $table = M($tableName, '', 'DB_CONFIG1');
        $pk = "";
        switch ($tableName){
            case "tcommand":
                $pk="GroupID";
                break;
            case "treseller":
                $pk="ResellerID";
                break;
            case "troom":
                $pk="RoomID";
                break;
            case "tstylecategory":
                $pk="StyleID";
                break;
        }
        if ($table->where($pk . "=" . $_POST[$pk])->find() != null) {
            $table->data($_POST)->save();
            echo "<script>alert('更新成功！')</script>";
        }
        else {
            $table->data($_POST)->add();
            echo "<script>alert('添加成功！')</script>";
        }
    }

    public function insertTcommand()
    {
        $this->insert("tcommand");
    }

    public function insertTreseller()
    {
        $this->insert("treseller");
    }

    public function insertTroom()
    {
        $this->insert("troom");
    }

    public function insertTstylecategory()
    {
        $this->insert("tstylecategory");
    }

    public function index()
    {
        //do nothing
    }
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PostTest</title>
</head>
<body>
		<form action="insertTcommand" method="post">
			<input type="submit" value="添加/修改tcommand表"> 
			<input type="text"name="GroupID" placeholder="GroupID"> 
			<input type="text" name="PNGFileName"placeholder="PNGFileName">
			<input type="text"name="PNGFilePath" placeholder="PNGFilePath"> 
			<input type="text"name="IsDone" placeholder="IsDone"> 
			<input type="date"name="CreateTime" placeholder="CreateTime"> 
		</form><br>
		<form action="insertTreseller" method="post">
			<input type="submit" value="添加/修改treseller表"> 
			<input type="text"name="ResellerID" placeholder="ResellerID"> 
			<input type="text" name="ResellerName"placeholder="ResellerName">
		</form><br>
		<form action="insertTroom" method="post">
			<input type="submit" value="添加/修改troom表"> 
			<input type="text"name="RoomID" placeholder="RoomID"> 
			<input type="text" name="RoomName"placeholder="RoomName">
			<input type="text" name="R_CategoryID"placeholder="R_CategoryID">
			<input type="number" name="RoomWidth"placeholder="RoomWidth">
			<input type="number" name="RoomLength"placeholder="RoomLength">
			<input type="number" name="RoomHeight"placeholder="RoomHeight">
		</form><br>
		<form action="insertTstylecategory" method="post">
			<input type="submit" value="添加/修改tstylecategory表"> 
			<input type="text"name="StyleID" placeholder="StyleID"> 
			<input type="text" name="StyleName"placeholder="StyleName">
		</form><br>
</body>
</html>